<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<c:set var="characterEncoding" value="UTF-8" scope="request"/>
<jsp:include page="/WEB-INF/common/urls.jsp"/>

<html lang="zh-CN">
<head>
    <title>${applicationScope.PROJECT_NAME}-登录</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, shrink-to-fit=no">
    <%--图标icon--%>
    <link rel="icon" href="${pageContext.request.contextPath}/favicon.ico" type="image/ico">
    <link rel="stylesheet"
          href="${pageContext.request.contextPath}/lib/bootstrap-5.3.0-alpha1-dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/global.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/authorization_style">
    <script src="${pageContext.request.contextPath}/lib/bootstrap-5.3.0-alpha1-dist/js/bootstrap.bundle.min.js"></script>
    <script src="${pageContext.request.contextPath}/lib/jquery-3.5.1.min.js"></script>
    <style>
        .container-div {
            display: grid;
            place-items: center;
            height: 100%;
            background: var(--bg);
            background-size: 120%;
        }

        .login-box {
            width: 100%;
            max-width: 400px;
            padding: 30px;
            background-color: rgba(255, 255, 255, 0.8);
            border-radius: 10px;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
            margin-top: -140px;
        }

        .form-signin {
            width: 100%;
        }

        .register-link {
            color: #6c757d;
            text-decoration: none;
            transition: color 0.15s ease-in-out;
            margin-left: 10px; /* 添加左边距 */
        }

        .register-link:hover {
            color: #5a6268;
            text-decoration: underline;
        }
    </style>
</head>
<script>
    $(() => {
        const refreshCaptcha = () => {
            const timestamp = new Date().getTime();
            $('#captchaImage').attr('src', "${publicUrl}/validate?" + timestamp);
        };

        $('#refreshLink, #captchaImage').on('click', (e) => {
            e.preventDefault();
            refreshCaptcha();
        });
    })
</script>
<body>
<div class="container-div">
    <div class="login-box">
        <main class="form-signin">
            <form method="post" action="${publicUrl}/login" accept-charset="UTF-8">
                <h1 class="h3 mb-4 fw-normal text-center">${applicationScope.PROJECT_NAME}</h1>

                <div class="text-center mb-3">
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" type="radio" name="role" id="userRole" value="user" checked>
                        <label class="form-check-label" for="userRole">用户</label>
                    </div>
                    <div class="form-check form-check-inline">
                        <input class="form-check-input" type="radio" name="role" id="adminRole" value="admin">
                        <label class="form-check-label" for="adminRole">管理员</label>
                    </div>
                </div>

                <div class="form-floating mb-3">
                    <input name="username" type="text" class="form-control" id="username" placeholder="用户名"
                           value="">
                    <label for="username">用户名</label>
                </div>
                <div class="form-floating mb-3">
                    <input name="password" type="password" class="form-control" id="password" placeholder="密码"
                           value="">
                    <label for="password">密码</label>
                </div>
                <div class="form-floating mb-3">
                    <input type="text" class="form-control" name="code" size="4" id="code">
                    <label for="code">验证码</label>
                </div>
                <div class="form-floating mb-3 d-flex align-items-end">
                    <img id="captchaImage" src="${publicUrl}/validate" alt="看不清楚" style="cursor: pointer;">
                    <a href="#" id="refreshLink" style="font-size: 16px">看不清，换一张</a>
                </div>

                <div class="d-flex align-items-end">
                    <button class="btn btn-primary" type="submit">登录</button>
                    <a href="register" class="register-link">没有账号？立即注册</a>
                </div>
            </form>
        </main>
    </div>
    <jsp:include page="/footer"/>
</div>
</body>
</html>